<?php
	include 'connection.php';
	include 'header.php';
	
	function getAllCategory($link) {
		$query 	= "SELECT * FROM event_detail";
		$result = mysql_query($query, $link);
		
		if(mysql_num_rows($result) > 0) {
			$response = array();
			$idx = 0;
			while($row = mysql_fetch_array($result)) {
				$response[$idx] = $row;
				$idx++;
			}
			$response['length'] = $idx;
			return json_encode($response);
		} else {
			return json_encode(array('status'=>'empty'));
		}
	}
	
	function getCategory($link, $id) {
		$query 	= "SELECT * FROM event_detail WHERE event_id = ".$id;
		$result = mysql_query($query, $link);
		
		if(mysql_num_rows($result) > 0) {
			$row = mysql_fetch_array($result);
			return json_encode($row);
		} else {
			return json_encode(array('status'=>'empty'));
		}
	}
	
	if(isset($_GET["q"])) {
		echo getCategory($link, $_GET["q"]);
	} else {
		echo getAllCategory($link);
	}

?>